package cn.ztr.ymcc.mq;

import cn.ztr.ymcc.constance.cons;
import cn.ztr.ymcc.domain.CourseOrder;
import cn.ztr.ymcc.mapper.CourseOrderMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.base.Charsets;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RocketMQMessageListener(
        consumerGroup = "PayTimeoutConsumerInCourseOrder",
        topic = cons.PAY_TIMEOUT_TOPIC_ZTR,
        selectorExpression = cons.PAY_TIMEOUT_TARGET_ZTR
)
public class PayTimeoutConsumer implements RocketMQListener<MessageExt> {

    @Autowired
    private CourseOrderMapper courseOrderMapper;
    @Override
    public void onMessage(MessageExt message) {
        byte[] body = message.getBody();
        String orderNo = new String(body, Charsets.UTF_8);
        CourseOrder courseOrder = courseOrderMapper.selectOne(new QueryWrapper<CourseOrder>().eq("order_no", orderNo));
        if (courseOrder.getStatusOrder()==0)
            courseOrderMapper.updateById(courseOrder.setStatusOrder(4));
    }
}
